package com.hzjh.h5mall.adapter.wallet

import android.view.View
import com.hzjh.base.ext.R
import com.hzjh.base.frame.adapter.BaseBindingVH
import com.hzjh.base.utils.function.visibleOrGone
import com.hzjh.h5mall.bean.WalletProcessStatus
import com.hzjh.h5mall.bean.wallet.WalletProcessBean
import com.hzjh.h5mall.databinding.ItemWalletProcessBinding

class WalletProcessVH(binding:ItemWalletProcessBinding,
                      private val clickFailed:(view:View,message:String)->Unit,
                      private val ifNotLast:(position:Int)->Boolean,) : BaseBindingVH<WalletProcessBean, ItemWalletProcessBinding>(binding) {
    override fun onBind(model: WalletProcessBean, position: Int) {
        binding.tvProcessItem.text=model.title
        binding.tvTimeItem.text=model.time
        binding.ivHelpTag.visibleOrGone(false)
        when(model.state){
            WalletProcessStatus.COMPLETE->{
                binding.ivStatusItem.setImageResource(R.drawable.svg_checkbox_success)
                binding.viewStatusItem.setBackgroundResource(com.hzjh.base.style.R.color.coreRed)
            }
            WalletProcessStatus.PROCESSING->{
                binding.ivStatusItem.setImageResource(R.drawable.svg_checkbox_ing)
                binding.viewStatusItem.setBackgroundResource(com.hzjh.base.style.R.color.coreLine2)
            }
            WalletProcessStatus.NOT_START->{
                binding.ivStatusItem.setImageResource(R.drawable.svg_checkbox_done)
                binding.viewStatusItem.setBackgroundResource(com.hzjh.base.style.R.color.coreLine2)
            }
            WalletProcessStatus.FAIL->{
                binding.ivStatusItem.setImageResource(R.drawable.svg_checkbox_fail)
                binding.viewStatusItem.setBackgroundResource(com.hzjh.base.style.R.color.coreLine2)
                binding.ivHelpTag.visibleOrGone(model.message.isNotEmpty()){
                    setOnClickListener {
                        clickFailed(it,model.message)
                    }
                }
            }
        }
        binding.viewStatusItem.visibleOrGone(ifNotLast.invoke(position))
    }
}